package org.jeese.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**  
 * 显示/隐藏枚举
 *     
 * @author wubc
 * @date 2018年9月4日 下午5:59:19   
 * @version V1.0 
 */  
public enum DisplayEnum {

	/** 隐藏 */
	HIDDEN("隐藏", 0), 
	/** 显示 */
	VISIBLE("显示", 1);

	/** 描述 */
	private String describe;
	/** 枚举值 */
	private int value;
	
	public final static Map<String, String> MAP = new LinkedHashMap<String, String>();

	private DisplayEnum(String describe, int value) {
		this.describe = describe;
		this.value = value;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public String getDescribe() {
		return describe;
	}

	public void setDescribe(String describe) {
		this.describe = describe;
	}
	
	static {
		for (DisplayEnum s : DisplayEnum.values()) {
			MAP.put(String.valueOf(s.getValue()), s.getDescribe());
		}
	}

	public static DisplayEnum getEnum(int value) {
		DisplayEnum resultEnum = null;
		DisplayEnum[] enumAry = DisplayEnum.values();
		for (int i = 0; i < enumAry.length; i++) {
			if (enumAry[i].getValue() == value) {
				resultEnum = enumAry[i];
				break;
			}
		}
		return resultEnum;
	}

	public static List<Map<String, String>> toList() {
		DisplayEnum[] ary = DisplayEnum.values();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for (int i = 0; i < ary.length; i++) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("value", String.valueOf(ary[i].getValue()));
			map.put("describe", ary[i].getDescribe());
			list.add(map);
		}
		return list;
	}

	public static Map<String, Map<String, Object>> toMap() {
		Map<String, Map<String, Object>> enumMap = new HashMap<String, Map<String, Object>>();
		for (DisplayEnum displayEnum : DisplayEnum.values()) {
			Map<String, Object> map = new HashMap<String, Object>();
			String key = String.valueOf(getEnum(displayEnum.getValue()));
			map.put("value", String.valueOf(displayEnum.getValue()));
			map.put("describe", displayEnum.getDescribe());
			enumMap.put(key, map);
		}
		return enumMap;
	}
	
	public static Map<String, Object> enumMap() {
		Map<String, Object> map = new LinkedHashMap<String, Object>();
		for (DisplayEnum displayEnum : DisplayEnum.values()) {
			map.put(String.valueOf(displayEnum.getValue()), displayEnum.getDescribe());
		}
		return map;
	}
	
	public static void main(String[] args) {
		System.out.println(DisplayEnum.values());
	}

}
